#!/bin/bash
#
# Rootfs mktree backend for use in throwaway build containers.
# Installs RPM into / and runs the test-suite against the same.
#
# PWD must be host-mounted for OverlayFS mounts to work.
# The / filesystem should be read-only to prevent parallel tests from altering
# it (online changes to an underlying filesystem are disallowed in OverlayFS).

DATA_DIR=/usr/share/mktree

CMD=$1; shift
case $CMD in
    build)
        source ./mktree.common
        make_install /

        mkdir -p $DATA_DIR
        cp $0 /usr/bin/
        cp rpmtests atlocal $DATA_DIR/
    ;;
    check)
        ln -s $DATA_DIR/* .
        ./rpmtests "$@"
        RC=$?
        cat rpmtests.log
        exit $RC
    ;;
    *)
        echo "Unsupported command." >&2
        exit 1
    ;;
esac
